<template>
  <HomePanel ref="target" title="新鲜好物" subTitle="新鲜出炉 品质靠谱">
    <!-- 右侧具名插槽 -->
    <template #right>
      <XtxMore style="line-height: 22px" />
    </template>
    <!-- 内容主体，对应默认插槽 -->
    <div class="home-new">
      <Transition name="fade">
        <ul class="goods-list" v-if="goodsList.length">
          <li v-for="item in goodsList" :key="item.id">
            <RouterLink :to="`/goods/${item.id}`">
              <img :src="item.picture" />
              <p class="name ellipsis">{{ item.name }}</p>
              <p class="price">&yen;{{ item.price }}</p>
            </RouterLink>
          </li>
        </ul>
        <HomeSkeleton v-else></HomeSkeleton>
      </Transition>
    </div>
  </HomePanel>
</template>

<script>
import HomePanel from './home-panel.vue'
import HomeSkeleton from './home-skeleton.vue'
import { getNewGoods } from '@/api/home.js'
import { useLazyData } from '@/utils/hoods.js'
export default {
  components: {
    HomePanel,
    HomeSkeleton
  },
  setup() {
    const { target, list: goodsList } = useLazyData(getNewGoods)
    return { target, goodsList }
  }
}
</script>

<style lang="less" scoped>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 100%;
    background: #f0f9f4;
    transition: all 0.5s;
    &:hover {
      transform: translate3d(0, -3px, 0px);
      box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
    }
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .price {
      color: var(--price-color);
    }
  }
}
</style>
